Data migration method and device

ABSTRACT

Embodiments of the present disclosure provide a data migration method and device, wherein the data migration method comprises: acquiring a migration request for a source database, creating a snapshot of to-be-migrated data in the source database and migrating the snapshot to a target database, reading a data migration log stored in a primary replica database of the source database and synchronizing the data migration log into the target database, and configuring a route for a target primary replica database of the target database according to routing rules of the primary replica database.

CROSS REFERENCE TO RELATED APPLICATIONS

This application claims priority to and is a continuation of PCT PatentApplication No. PCT/CN2021/094094, filed on 17 May 2021 and entitled“DATA MIGRATION METHOD AND DEVICE,” which claims priority to ChinesePatent Application No. 202010477729.3, filed on 29 May 2020 and entitled“DATA MIGRATION METHOD AND DEVICE,” which are incorporated herein byreference in their entirety.

TECHNICAL FIELD

The embodiments of the present disclosure relate to the technical fieldof databases, and, more particularly, to data migration methods. One ormore embodiments of the present disclosure further relate to datamigration apparatuses, computing device, and computer-readable storagemedium.

BACKGROUND

With the development of science and technology, the Internet has beendeeply involved in all aspects of social life, bringing greatconvenience to people's work, life, study, and the like. In Internetbusiness operations, data traffic surges (a large increase in thedatabase capacity requirement) or data traffic plummets (a decrease inthe database capacity requirement) often occur in some specific timeperiods.

In order to meet elastic requirements, it is generally necessary for adistributed database to have the linear capability of scale-in/scale-outof nodes. In the process of scaling, in order to balance the storage andcomputing loads, data migration needs to be performed between nodes, andthe efficiency of data migration affects the availability andperformance of a system during linear scaling. For example, if acommunication link is used to directly transmit data blocks, the sizesof their data fragments are limited due to the short delay required bythe communication link, leading to a lack of flexibility; or,synchronization and communication links may be blocked when a data setis large, affecting the efficiency of data synchronization. Therefore,there is an urgent need for a data migration method to overcome suchproblems.

SUMMARY

This Summary is provided to introduce a selection of concepts in asimplified form that are further described below in the DetailedDescription. This Summary is not intended to identify all key featuresor essential features of the claimed subject matter, nor is it intendedto be used alone as an aid in determining the scope of the claimedsubject matter. The term “technique(s) or technical solution(s)” forinstance, may refer to apparatus(s), system(s), method(s) and/orcomputer-readable instructions as permitted by the context above andthroughout the present disclosure.

The embodiments of the present disclosure provide data migrationmethods. One or more embodiments of the present disclosure furtherrelate to data migration devices, computing device, andcomputer-readable storage medium, so as to solve the technical defectsexisting in the conventional techniques.

According to an embodiment of the present disclosure, a data migrationmethod is provided, comprising:

acquiring a migration request for a source database;

creating a snapshot of to-be-migrated data in the source database andmigrating the snapshot to a target database;

reading a data migration log stored in a primary replica database of thesource database and synchronizing the data migration log into the targetdatabase; and

configuring a route for a target primary replica database of the targetdatabase according to routing rules of the primary replica database.

For example, the source database includes the primary replica databaseand at least one secondary replica database; and the target databaseincludes at least two replica databases.

For example, the data migration log is synchronized into the targetdatabase by:

establishing a log synchronization link based on the primary replicadatabase, the at least one secondary replica database, and the at leasttwo replica databases; and

synchronizing the data migration log into the target database accordingto an upstream-downstream connection relationship of each node in thelog synchronization link.

For example, the synchronizing the data migration log into the targetdatabase according to an upstream-downstream connection relationship ofeach node in the log synchronization link comprises:

synchronizing the data migration log from the primary replica databaseinto the at least one secondary replica database; and

synchronizing the data migration log from the at least one secondaryreplica database into the at least two replica databases.

For example, the configuring a route for a target primary replicadatabase of the target database according to routing rules of theprimary replica database comprises:

determining any of the replica databases contained in the targetdatabase as the target primary replica database; and

configuring a route for the target primary replica database according tothe routing rules of the primary replica database.

For example, the target primary replica database is determined by:

initiating an election to the source database based on identificationinformation of the at least two replica databases, wherein the electionis used to elect the target primary replica database from the at leasttwo replica databases;

acquiring voting results submitted by the primary replica database andthe at least one secondary replica database; and

counting the voting results, and determining one of the at least tworeplica databases first obtaining more votes than a preset threshold asthe target primary replica database.

For example, the creating a snapshot of to-be-migrated data in thesource database and migrating the snapshot to a target databasecomprises:

creating a snapshot of full to-be-migrated data in the primary replicadatabase or any secondary replica database of the source database; and

migrating the snapshot to the target database by a preset migrationmode.

For example, it further comprises, after the step of reading a datamigration log stored in a primary replica database of the sourcedatabase and synchronizing the data migration log into the targetdatabase is performed and before the step of configuring a route for atarget primary replica database of the target database according torouting rules of the primary replica database is performed:

judging whether the number of synchronized log entries in the datamigration log meets a preset threshold; and

if so, determining that a synchronization progress of the data migrationlog meets a preset progress threshold, and performing the step ofconfiguring the route for the target primary replica database of thetarget database according to the routing rules of the primary replicadatabase in the source database.

For example, the method further comprises, after the step of configuringa route for a target primary replica database of the target databaseaccording to routing rules of the primary replica database in the sourcedatabase is performed:

receiving a data read-write request;

searching a corresponding target primary replica database according toan identifier of requested data in the data read request; and

performing a data read-write operation on the target primary replicadatabase according to routing rules for data read-write of the targetprimary replica database.

According to an embodiment of the present disclosure, a data migrationdevice is provided, comprising:

an acquisition module, configured to acquire a migration request for asource database;

a creation module, configured to create a snapshot of to-be-migrateddata in the source database and migrate the snapshot to a targetdatabase;

a reading module, configured to read a data migration log stored in aprimary replica database of the source database and synchronize the datamigration log into the target database; and

a configuration module, configured to configure a route for a targetprimary replica database of the target database according to routingrules of the primary replica database.

According to an embodiment of the present disclosure, a computing deviceis provided, comprising:

a memory and a processor;

wherein the memory is configured to store computer-executableinstructions, and the processor is configured to execute thecomputer-executable instructions to:

acquire a migration request for a source database;

create a snapshot of to-be-migrated data in the source database andmigrate the snapshot to a target database;

read a data migration log stored in a primary replica database of thesource database and synchronize the data migration log into the targetdatabase; and

configure a route for a target primary replica database of the targetdatabase according to routing rules of the primary replica database.

According to an embodiment of the present disclosure, acomputer-readable storage medium having computer-executable instructionsstored thereon, which, when executed by a processor, implement the stepsof the data migration method is provided.

In one embodiment of the present disclosure, a method includes acquiringa migration request for a source database, creating a snapshot ofto-be-migrated data in the source database and migrating the snapshot toa target database, reading a data migration log stored in a primaryreplica database of the source database and synchronizing the datamigration log into the target database, and configuring a route for atarget primary replica database of the target database according torouting rules of the primary replica database.

By using the techniques of the present disclosure, to-be-migrated datain the source database are fully migrated to the target database throughsnapshot export, and in addition, the data migration log is synchronizedin an incremental synchronization manner and route switching isperformed in the log synchronization process, which, on the one hand,avoids blocking a synchronization link for incremental synchronizationand thus advantageously improves the efficiency of log synchronization,and on the other hand, allows for normal data read-write in the fullmigration process as no routing switching is performed in the fullmigration process and thus advantageously improves data read-write.

BRIEF DESCRIPTION OF DRAWINGS

To describe the technical solutions in the embodiments of the presentdisclosure more clearly, the following briefly describes theaccompanying drawings required for describing the embodiments.Apparently, the accompanying drawings in the following description aremerely some embodiments of the present disclosure, and those of ordinaryskills in the art may further derive other accompanying drawings fromthese accompanying drawings without inventive efforts.

FIG. 1 is a processing flowchart of a data migration method according toan embodiment of the present disclosure;

FIG. 2 is a schematic diagram of a database expansion process accordingto an embodiment of the present disclosure;

FIG. 3 is a flowchart of a processing process of a data migration methodaccording to an embodiment of the present disclosure;

FIG. 4 is a schematic diagram of a data migration device according to anembodiment of the present disclosure; and

FIG. 5 is a structural block diagram of a computing device according toan embodiment of the present disclosure.

DESCRIPTION OF EMBODIMENTS

In the following description, many specific details are explained inorder for those skilled in the art to fully understand the presentdisclosure. However, the present disclosure can be implemented in manyother manners different from those described herein. Those skilled inthe art may make similar generalization without departing from thespirit of the present disclosure. Therefore, the present disclosure isnot limited by the specific implementations disclosed below.

The terms used in one or more embodiments of the present disclosure areonly for the purpose of describing specific embodiments, and are notintended to limit one or more embodiments of the present disclosure.Unless the context clearly dictates otherwise, the singular forms “a,”“said,” and “the” used in one or more embodiments of the presentdisclosure and the appended claims are also intended to include theplural forms. It should also be appreciated that the term “and/or” usedin one or more embodiments of the present disclosure refers to andincludes any or all possible combinations of one or more associatedlisted items.

It should be appreciated that, although the terms “first,” “second,” andthe like may be used to describe various information in one or moreembodiments of the present disclosure, such information should not belimited to these terms. These terms are only used to distinguish thesame type of information from each other. For example, without departingfrom the scope of one or more embodiments of the present disclosure,“first” may also be referred to as “second.” Similarly, “second” mayalso be referred to as “first.” Depending on the context, the word “if”as used herein may be interpreted as “when” or “in the case that” or “inresponse to a determination.”

First, the terms involved in one or more embodiments of the presentdisclosure are explained below.

Raft algorithm: a consensus algorithm that provides a general method fordistributing state machines in a cluster of computing systems so as toensure that each node in the cluster can achieve the same statetransitions.

Data mirroring backup tool: an efficient tool for data transfer and filesynchronization, which is written in C language, and widely integratedand used in Unix-like operating systems.

In the present disclosure, a data migration method is provided, and thepresent disclosure further relates to a data migration device, acomputing device, and a computer-readable storage medium, as describedin further detail one by one in the following embodiments.

FIG. 1 shows a processing flowchart of a data migration method accordingto an embodiment of the present disclosure, including steps 102-108.

Step 102, acquiring a migration request for a source database.

With the development of science and technology, the Internet has beendeeply involved in all aspects of social life, bringing greatconvenience to people's work, life, study, and the like. In Internetbusiness operations, data traffic surges (a large increase in thedatabase capacity requirement) or data traffic plummets (a decrease inthe database capacity requirement) often occur in some specific timeperiods.

In order to meet elastic requirements, it is generally necessary for adistributed database to have the linear capability of scale-in/scale-outof nodes. In the process of scaling, in order to balance the storage andcomputing loads, data migration needs to be performed between nodes, andthe efficiency of data migration affects the availability andperformance of a system during linear scaling.

Based on this, the data migration method according to the embodiments ofthe present disclosure is applied to a distributed database system,to-be-migrated data in a source database are fully migrated to a targetdatabase through snapshot export, and in addition, the data migrationlog is synchronized in an incremental synchronization manner and routeswitching is performed in the log synchronization process, which, on theone hand, avoids blocking a synchronization link for incrementalsynchronization and thus advantageously improves the efficiency of logsynchronization, and on the other hand, allows for normal dataread-write in the full migration process because no routing switching isperformed in the full migration process and thus advantageously improvesdata read-write.

In order to ensure high availability of the distributed database systemduring linear scaling, the data migration method according to theembodiments of the present disclosure adopts a full-incremental datamigration manner, such that the system availability is not affectedthroughout the migration process or the routing switching process.

In particular, the data migration refers to migrating the data in thesource database to the target database, wherein the source databaseincludes the primary replica database and at least one secondary replicadatabase, and the target database includes at least two replicadatabases; and after acquiring a migration request for the sourcedatabase, a snapshot of the full data in the source database can becreated, and the data in the source database can be fully migrated tothe target database in a snapshot migration manner.

Step 104, creating a snapshot of to-be-migrated data in the sourcedatabase and migrating the snapshot to a target database.

In particular, since the source database comprises one primary replicadatabase and at least one secondary replica database, in specificimplementations, creating a snapshot of to-be-migrated data in thesource database and migrating the snapshot to a target database afteracquiring a migration request for the source database refers to creatinga snapshot of the full data to be migrated in the primary replicadatabase or any secondary replica database of the source database andmigrating the snapshot to the target database by a preset migrationmode.

Further, since the data stored in the primary replica database and theat least one secondary replica database of the source database are thesame, in the data migration process, only the data in any one of theprimary replica database or the at least one secondary replica databaseof the source database need to be synchronized. Therefore, creating asnapshot of to-be-migrated data in the source database refers tocreating a snapshot of full to-be-migrated data in the primary replicadatabase or any secondary replica database of the source database. Afterthe snapshot is created, the snapshot is migrated in parallel to the atleast two replica databases of the target database by the presetmigration mode. In specific implementations, the preset migration methodmay be adopting a data mirroring backup tool (rsync tool), that is, thersync tool is adopted to perform full data migration.

Before the data migration is completed, the data reading and writingfunctions are provided by the source database. Therefore, beforeswitching the route from the source database to the target database, theprimary replica database and the at least one secondary replica databaseof the source database have an active state (active to handle dataread-write requests), while the at least two replica databases of thetarget database have a passive state (idle state) and are in preparationfor changing their states to active.

Step 106, reading a data migration log stored in a primary replicadatabase of the source database and synchronizing the data migration loginto the target database.

In particular, the data migration log is a file separated from thedatabase file. The data migration log stores all changes made to thedatabase, and records all insertions, updates, deletions, submissions,rollbacks, and database schema changes. The data migration log is a keycomponent for data/file backup and recovery, so the data migration logneeds to be incrementally migrated to (synchronized into) the targetdatabase after the data in the source database are fully migrated to thetarget database.

In specific implementations, the raft algorithm can be adopted tosynchronize the data migration log. The raft algorithm divides roles inthe distributed database system into leaders (leader nodes), followers(follower nodes), and candidates (candidate nodes). In the embodimentsof the present disclosure, the primary replica database included in thesource database is a leader node, and the at least one secondary replicadatabase included in the source database is a follower node. Since thereis no target primary replica database in the target database before thedata migration log is synchronized into the target database, the atleast two replica databases included in the target database are in apassive state before the data migration log is synchronized into thetarget database, and the at least two replica databases of the targetdatabase change their states from passive to active after the datamigration log is synchronized into the target database. Then, the atleast two replica databases can be used as targets to which the leadernode can switch (that is, the at least two replica databases can be usedas candidate nodes).

In the raft algorithm, the leader node is used to receive a dataread-write request sent by a client and synchronize the data migrationlog into the follower nodes, and when the data migration log issynchronized into a majority of nodes, the leader node can send thefollower nodes prompt information for log submission; the follower nodesare used to receive and persist the data migration log synchronized bythe leader node, and submit the log after receiving the promptinformation for log submission sent by the leader node; and thecandidate nodes are temporary roles in the process for electing a leadernode.

The states of the leader node and follower nodes in the source databaseare active, and the states of the at least two replica databases of thetarget database are passive. The at least two replica databases includedin the target database are in a passive state before the data migrationlog is synchronized into the target database, and once the at least tworeplica databases of the target database change their states frompassive to active after the data migration log is synchronized into thetarget database, the at least two replica databases can be used ascandidate nodes. The leader node and follower nodes in the sourcedatabase are used to make an election for the at least two replicadatabases of the target database when the log synchronization progressmeets a preset threshold, that is, to elect the target primary replicadatabase in the candidate nodes.

In practical applications, the synchronization mechanism of raft-log canbe used to synchronize the data migration log. Since there can only beat most one leader node in the raft distributed database system, the logcan only be copied from the leader node to the follower nodes. Anapplication scenario of the raft algorithm is a replicated statemachine, in which a client (participant) sends commands to be executedon the state machine to the replicated state machine, and the raftalgorithm is responsible for copying the commands to other statemachines in the form of logs. If different state machines execute thesecommands in a consistent order, the same output results can be obtained.Therefore, a consensus algorithm can be used to ensure that the contentsand orders of the synchronized data migration logs are consistent.

In specific implementations, a log synchronization link can be used tosynchronize the data migration log, and therefore, a log synchronizationlink needs to be established before synchronizing the log, and the logis synchronized into the target database through the log synchronizationlink, which can be particularly implemented by:

establishing a log synchronization link based on the primary replicadatabase, the at least one secondary replica database, and the at leasttwo replica databases; and

synchronizing the data migration log into the target database accordingto an upstream-downstream connection relationship of each node in thelog synchronization link.

Further, synchronizing the data migration log into the target databaseaccording to an upstream-downstream connection relationship of each nodein the log synchronization link can be particularly implemented by:

synchronizing the data migration log from the primary replica databaseinto the at least one secondary replica database; and

synchronizing the data migration log from the at least one secondaryreplica database into the at least two replica databases.

In particular, the data migration log is a file separated from thedatabase file. The data migration log stores all changes made to thedatabase, and records all insertions, updates, deletions, submissionsand rollbacks performed on data in the database, and database schemachanges. The data migration log is a key component for data/file backupand recovery, and the log is stored in the leader node. The leader nodesynchronizes the log into the follower nodes, and the follower nodessynchronize the log into the at least two replica databases of thetarget database. Therefore, a log synchronization link needs to beestablished before synchronizing the data migration log based on theprimary replica database, the at least one secondary replica database,the at least two replica databases, and a synchronization order of thedata migration log among various nodes, and after the logsynchronization link is established, the data migration log can besynchronized into the target database according to anupstream-downstream connection relationship of each node in the link.

Step 108, configuring a route for a target primary replica database ofthe target database according to routing rules of the primary replicadatabase.

In particular, since the data migration log includes log entries withsequential log indexes, the synchronization of the data migration log isactually the synchronization of each log entry in the log. If the numberof synchronized log entries meets a preset threshold, a route can beconfigured for the replica databases of the target database, that is,the route of the primary replica database in the source database isswitched to the target primary replica database of the target database,and the route can provide data reading and writing functions.

In specific implementations, since the data migration log includes logentries, the synchronization progress of the data migration log can bedetermined by:

judging whether the number of synchronized log entries in the datamigration log meets a preset threshold; and

if so, determining that the synchronization progress of the datamigration log meets a preset progress threshold, and configuring theroute for the target primary replica database of the target databaseaccording to the routing rules of the primary replica database in thesource database.

In particular, since the synchronization of the data migration log isactually the synchronization of each log entry in the log, the processof judging whether the number of synchronized log entries in the datamigration log meets a preset threshold can be performed simultaneouslywith the process of synchronizing the data migration log into the targetdatabase. If the number of synchronized log entries is judged to meetthe preset threshold, route switching can be performed in the logsynchronization process, that is, the route can be switched from thesource database to the target database; and if the number ofsynchronized log entries is judged not to meet the preset threshold, thelog synchronization process can continue.

The client initiating three writing requests is taken as an example,after receiving these requests, the leader node first synchronizes therequests into the follower nodes in batches in the form of logs, thenupdates log sites after receiving the follower nodes' responseindicating a successful log replication, and finally adds theinstructions sent by the client to a counter through invoking aninterface to execute a counting operation in the requests.

Updating log sites indicates that the logs before the log sites(inclusive) have all been copied to more than half of the nodes in thesystem. If the site is the position of “2,” it indicates that the logsof “0-2” have all been copied to more than half of the nodes. If theleader continues to copy the two logs “3” and “4” to the follower nodesin batches, then the site slides to the position of “4,” indicating thatthe logs of “0-4” have all been copied to more than half of the nodes.

When the difference between log sites of at least one replica databasein a target database and log sites of a primary replica database in asource database is less than a preset threshold (100), a leader node inthe source database initiates a member change operation, that is, thestate of at least one secondary replica database in the source databaseis switched from active to passive, the states of at least two replicadatabases in the target database are switched from passive to active,and the roles of the at least two replica databases are changed tofollower nodes.

In addition, the target primary replica database of the target databasecan be determined through election, which can be particularlyimplemented by:

initiating an election to the source database based on identificationinformation of the at least two replica databases, wherein the electionis used to elect the target primary replica database from the at leasttwo replica databases;

acquiring voting results submitted by the primary replica database andthe at least one secondary replica database; and

counting the voting results, and determining one of the at least tworeplica databases first obtaining more votes than a preset threshold asthe target primary replica database.

In particular, the counting of the voting results is dynamicallyperformed along with the voting process. The primary replica databaseand the at least one secondary replica database in the source databasevote on the at least two replica databases in the target database, andthe target primary replica database in the target database is determinedaccording to the voting results, that is, in the voting process, thenumber of votes of the at least two replica databases in the targetdatabase are dynamically counted, and the replica database in the atleast two replica databases first obtaining more votes than the presetthreshold is determined as the target primary replica database.

In practical applications, raft triggers a leader election throughheartbeats, initializes the roles of the at least two replica databasesin the target database as follower nodes, appoints the primary replicadatabase and the at least one secondary replica database in the sourcedatabase as voting members to vote on the follower nodes in the targetdatabase, and generates the target primary replica database in thetarget database.

After the voting results are acquired from the voting members, thevoting results are counted, and the follower node in the target databasefirst obtaining more votes than a preset threshold is determined as aleader node. In practical applications, the preset threshold can bedetermined according to the number of replica databases in the sourcedatabase, for example, if the source database includes 3 replicadatabases (1 primary replica database and 2 secondary replicadatabases), the preset threshold can be set to 2 (the voting rate isgreater than 50%), and the follower node in the target database firstobtaining more than 2 votes is determined as the leader node.

The voting can be based on the synchronization progress of the datamigration log in each node, that is, a follower node with the mostsynchronized log entries has a higher probability of changing to aleader node.

In addition, since the leader node is used to receive data read-writerequests from the client, after the route is switched to the targetprimary replica database (leader node) in the target database, thetarget primary replica database can be used to receive data read-writerequests from the client, and the process of handling the dataread-write requests can be particularly implemented by:

receiving a data read-write request;

searching a corresponding target primary replica database according toan identifier of requested data in the data read request; and

performing a data read-write operation on the target primary replicadatabase according to routing rules for data read-write of the targetprimary replica database.

In particular, after configuring the route for the target primaryreplica database of the target database, the target primary replicadatabase (leader node) can provide data reading and writing services,and the leader node adds the requests to its log in the form of logentries, and then synchronizes the log entries in parallel into otherfollower nodes. When this log is synchronized into a majority offollower nodes, the leader node applies this log to its state machineand returns the execution result to the client.

In particular, the embodiments of the present disclosure are describedby taking the source database including 3 replica databases as anexample. The schematic diagram of the expansion process of thedistributed database system is shown in FIG. 2 . The distributeddatabase system shown in FIG. 2 includes four source databases, namely,DB1 202, DB2 204, DB3 206, and DB4 208, and the data migration processof DB2 204 is taken as an example for schematic illustration. The datamigration process of DB1 202, DB3 206, and DB4 208 is similar to thedata migration process of DB2 204, and will not be repeated here.

In FIG. 2 , both the source database DB2 204 and the target databaseDB2-1 210 contain 3 replica databases. The 3 replica databases of thesource database DB2 204 are DB2 204(1), DB2 204(2), and DB2 204(3). The3 replica databases of the target database DB2-1 210 are DB2-1 210(1),DB2-1 210(2), and DB2-1 210(3).

Before the routing configuration is performed on the target databaseDB2-1 210, one replica database in the source database DB2 204 is theprimary replica database (leader node) 204(1), and the remaining tworeplica databases DB2 204(2) and DB2 204(3) are secondary replicadatabases (follower nodes). After a data migration request for thesource database DB2 204 is acquired, a snapshot of full to-be-migrateddata in the primary replica database or any secondary replica databaseis created, and the snapshot is migrated in parallel to 3 replicadatabases DB2-1 210(1), DB2-1 210(2), DB2-1 210(3) of the targetdatabase DB2-1 210 by adopting the data mirroring backup tool such asthe rsync tool; after the migration is completed, the data slice rafthas 6 replica databases, wherein the 3 replica databases 204(1), 204(2),204(3) in the source database 204 are still in an active state, and the3 replicas 210(1), 210(2), 210(3) in the target database 210 are in apassive state; the data migration log of the leader node 204(1) in thesource database 204 is read, and the data migration log is incrementallymigrated to the target database 210. Incremental migration uses thesynchronization mechanism of raft-log. The data migration log issynchronized from the replica database of the source database into thetarget database through the log synchronization link. When the log siteof any replica database in the target database is close to the site ofthe primary replica database (leader node) 204(1) of the source database204 (the difference between the sites is less than a preset thresholdsuch as 100), the leader node 204(1) initiates a member changeoperation, and the state of the other 2 follower nodes 204(2) and 204(3)in the source databases 204 is switched from active to passive, thestate of the 3 replica databases 210(1), 210(2), and 210(3) of thetarget database 210 is switched from passive to active, and the roles ofthe 3 replica databases 210(1), 210(2), and 210(3) are switched tofollower nodes.

After the state of each replica database in the source database 204 andthe target database 210 is changed, the leader node initiates anelection to the source database 204 based on identification informationof any replica database (follower node) in the target database 210, andthe any replica database is determined as the target primary replicadatabase. That is, the primary replica database in the source database204 actively migrates the leader to any replica database, such as 210(1)in the target database 210, and such replica database is changed from afollower node to a leader node after the migration.

After the target primary replica database (new leader node) 210(1) isdetermined among the 3 follower nodes, routing configuration isperformed on the target primary replica database according to therouting rules of the leader node in the source database.

The controller 212 is used to manage read-write routing, that is, it isused to determine which node the fragmented data to be read/writtenfalls on. The controller 212 is used to receive data read-writerequests. After a read-write request is sent to the controller 212, thecontroller 212 allocates read-write tasks, and therefore, so as long asthe read-write routing information is stored on the controller 212, thecontroller 212 can find the replica database related to the read-writerequests. Therefore, when the route is switched, the new leader node210(1) immediately initiates a heartbeat to inform the controller 212 ofthe result of the route switching, based on which the controller 212updates its own routing information.

In one embodiment of the present disclosure, by acquiring a migrationrequest for performing data migration on a source database, creating asnapshot of to-be-migrated data in the source database and migrating thesnapshot to a target database, reading a data migration log stored in aprimary replica database of the source database and synchronizing thedata migration log into the target database, and configuring a route fora target primary replica database of the target database according torouting rules of the primary replica database when the synchronizationprogress of the data migration log meets a preset progress threshold,

the data in the source database are fully migrated to the targetdatabase through snapshot export, and in addition, the data migrationlog is synchronized in an incremental synchronization manner and routeswitching is performed in the log synchronization process, which, on theone hand, avoids blocking a synchronization link for incrementalsynchronization and thus advantageously improves the efficiency of logsynchronization, and on the other hand, allows for normal dataread-write in the full migration process because no routing switching isperformed in the full migration process and thus advantageously improvesdata read-write.

The data migration method will be further described below by taking theapplication of the data migration method provided in the presentdisclosure as an example in conjunction with FIG. 3 . FIG. 3 shows aflowchart of a processing process of a data migration method accordingto an embodiment of the present disclosure, specifically including steps302-316.

Step 302, acquiring a migration request for a source database.

Step 304, creating a snapshot of full to-be-migrated data in the primaryreplica database or any secondary replica database in the sourcedatabase.

Step 306, migrating the snapshot to at least one replica database in thetarget database according to a preset migration mode.

Step 308, reading a data migration log stored in the primary replicadata of the source database.

Step 310, establishing a log synchronization link based on the primaryreplica database, the at least one secondary replica database, and theat least two replica databases.

Step 312, synchronizing the data migration log into the target databaseaccording to an upstream-downstream connection relationship of each nodein the log synchronization link.

In particular, the data migration log is synchronized from the primaryreplica database into the at least one secondary replica database, andthe data migration log is synchronized from the at least one secondaryreplica database into the at least two replica databases.

Step 314, judging whether the number of synchronized log entries in thedata migration log meets a preset threshold; if so, performing step 316.

In particular, if it is judged that the number of the synchronized logentries in the data migration log does not meet the preset threshold,the log synchronization is continued; if it is judged that the number ofthe synchronized log entries in the data migration log meets the presetthreshold, route switching can be performed simultaneously with the logsynchronization, that is, the read-write routing of the primary replicadatabase in the source database is switched to the target primaryreplica database of the target database.

Step 316, determining any of the replica databases contained in thetarget database as the target primary replica database, and performingrouting configuration for the target primary replica database accordingto the routing rules of the primary replica database.

In the embodiments of the present disclosure, the data in the sourcedatabase are fully migrated to the target database through snapshotexport, and in addition, the data migration log is synchronized in anincremental synchronization manner and route switching is performed inthe log synchronization process, which, on the one hand, avoids blockinga synchronization link for incremental synchronization and thusadvantageously improves the efficiency of log synchronization, and onthe other hand, allows for normal data read-write in the full migrationprocess because no routing switching is performed in the full migrationprocess and thus advantageously improves data read-write.

Corresponding to the method embodiments, the present disclosure furtherprovides an embodiment of a data migration device, and FIG. 4 shows aschematic diagram of a data migration device according to an embodimentof the present disclosure. As shown in FIG. 4 , the device 400 includesone or more processor(s) 402 or data processing unit(s) and memory 404.The device 400 may further include one or more input/output interface(s)406 and one or more network interface(s) 408. The memory 404 is anexample of computer-readable media.

Computer-readable media further include non-volatile and volatile,removable and non-removable media employing any method or technique toachieve information storage. The information may be computer-readableinstructions, data structures, modules of programs, or other data.Examples of computer storage media include, but are not limited to, aphase-change random access memory (PRAM), a static random access memory(SRAM), a dynamic random access memory (DRAM), other types of randomaccess memories (RAM), a read-only memory (ROM), an electricallyerasable programmable read-only memory (EEPROM), a flash memory or othermemory technologies, a compact disc read-only memory (CD-ROM), a digitalversatile disc (DVD) or other optical memories, a magnetic cassettetape, a magnetic tape, a magnetic disk storage or other magnetic storagedevices, or any other non-transmission medium, which may be used tostore information that can be accessed by a computing device. As definedherein, the computer-readable media do not include transitory media,such as modulated data signals and carriers.

The memory 404 may store therein a plurality of modules or unitsincluding:

an acquisition module 410 configured to acquire a migration request 412for a source database;

a creation module 414 configured to create a snapshot 416 ofto-be-migrated data in the source database and migrate the snapshot 416to a target database;

a reading module 418, configured to read a data migration log 420 storedin a primary replica database of the source database and synchronize thedata migration log 420 into the target database; and

a configuration module 422 configured to configure a route for a targetprimary replica database of the target database according to routingrules 424 of the primary replica database.

For example, the source database includes the primary replica databaseand at least one secondary replica database; and the target databaseincludes at least two replica databases.

For example, the reading module 418 comprises:

an establishment submodule, configured to establish a logsynchronization link based on the primary replica database, the at leastone secondary replica database, and the at least two replica databases;and

a synchronization submodule, configured to synchronize the datamigration log into the target database according to anupstream-downstream connection relationship of each node in the logsynchronization link.

For example, the synchronization submodule comprises:

a first synchronization unit, configured to synchronize the datamigration log from the primary replica database into the at least onesecondary replica database; and

a second synchronization unit, configured to synchronize the datamigration log from the at least one secondary replica database into theat least two replica databases.

For example, the configuration module 422 comprises:

a determination submodule, configured to determine any of the replicadatabases contained in the target database as the target primary replicadatabase; and

a configuration submodule, configured to configure a route for thetarget primary replica database according to the routing rules of theprimary replica database.

For example, the target primary replica database is determined by:

initiating an election to the source database based on identificationinformation of the at least two replica databases, wherein the electionis used to elect the target primary replica database from the at leasttwo replica databases;

acquiring voting results submitted by the primary replica database andthe at least one secondary replica database; and

counting the voting results, and determining one of the at least tworeplica databases first obtaining more votes than a preset threshold asthe target primary replica database.

For example, the creation module 414 comprises:

a creation submodule, configured to create a snapshot of fullto-be-migrated data in the primary replica database or any secondaryreplica database of the source database; and

a migration submodule, configured to migrate the snapshot to the targetdatabase by a preset migration mode.

For example, the data migration device further comprises:

a judgment module, configured to judge whether the number ofsynchronized log entries in the data migration log meets a presetthreshold; and

determine that a synchronization progress of the data migration logmeets a preset progress threshold if the running result of the judgmentmodule is yes, and perform the step of configuring the route for thetarget primary replica database of the target database according to therouting rules of the primary replica database in the source database.

For example, the device 400 may further comprise the following modulesstored in the memory 404:

a receiving module, configured to receive a data read-write request;

a searching module, configured to search a corresponding target primaryreplica database according to an identifier of requested data in thedata read request; and

a performing module, configured to perform a data read-write operationon the target primary replica database according to routing rules fordata read-write of the target primary replica database.

The above is a schematic solution of a data migration device accordingto this embodiment. It should be noted that the technical solution ofthe data migration device belongs to the same concept as the technicalsolution of the data migration method described above, and for detailsthat are not described in detail in the technical solution of the datamigration device, reference may be made to the description of thetechnical solution of the data migration method described above.

FIG. 5 shows a structural block diagram of a computing device 500provided according to an embodiment of the present disclosure.Components of the computing device 500 include, but are not limited to,a memory 510 and a processor 520. The processor 520 is connected withthe memory 510 through a bus 530, and a database 550 is used for savingdata.

The computing device 500 further includes an access device 540, whereinthe access device 540 enables the computing device 500 to communicatevia one or more networks 560. Examples of such networks include a publicswitched telephone network (PSTN), a local area network (LAN), a widearea network (WAN), a personal area network (PAN), or a combination ofcommunication networks such as the Internet. The access device 540 mayinclude one or more of any type of wired or wireless network interfaces(e.g., a network interface card (NIC)), such as an IEEE802.11 wirelesslocal area network (WLAN) wireless interface, a worldwideinteroperability for microwave access (Wi-MAX) interface, an Ethernetinterface, a universal serial bus (USB) interface, a cellular networkinterface, a Bluetooth interface, and a near field communication (NFC)interface.

In one embodiment of the present disclosure, the above components of thecomputing device 500 and other components not shown in FIG. 5 may alsobe connected to each other, such as through a bus. It should beunderstood that the structural block diagram of the computing deviceshown in FIG. 5 is only for the purpose of example, rather than limitingthe scope of the present disclosure. Other components may be added orreplaced as desired by those skilled in the art.

The computing device 500 may be any type of stationary or mobilecomputing device, including a mobile computer or mobile computing device(e.g., a tablet computer, a personal digital assistant, a laptopcomputer, a notebook computer, and a netbook), a mobile phone (e.g., asmartphone), a wearable computing device (e.g., a smartwatch and a pairof smart glasses), or other types of mobile devices, or a stationarycomputing device such as a desktop computer or PC. The computing device500 may also be a mobile or stationary server.

The memory 510 is configured to store computer-executable instructions,and the processor 520 is configured to execute the computer-executableinstructions to:

acquire a migration request for performing data migration on a sourcedatabase;

create a snapshot of the data in the source database and migrate thesnapshot to a target database;

read a data migration log stored in a primary replica database of thesource database and synchronize the data migration log into the targetdatabase; and

configure a route for a target primary replica database of the targetdatabase according to routing rules of the primary replica database.

The above is a schematic solution of a computing device according tothis embodiment. It should be noted that the technical solution of thecomputing device belongs to the same concept as the technical solutionof the data migration method described above, and for details that arenot described in detail in the technical solution of the computingdevice, reference may be made to the description of the technicalsolution of the data migration method described above.

An embodiment of the present disclosure further provides acomputer-readable storage medium having computer instructions storedthereon, which, when executed by a processor, is configured to implementthe steps of the data migration method.

The above is a schematic solution of a computer-readable storage mediumaccording to this embodiment. It should be noted that the technicalsolution of the storage medium belongs to the same concept as thetechnical solution of the data migration method described above, and fordetails that are not described in detail in the technical solution ofthe storage medium, reference may be made to the description of thetechnical solution of the data migration method described above.

The above describes specific embodiments of the present disclosure.Other embodiments fall within the protection scope of the appendedclaims. In some cases, the actions or steps stated in the claims may beperformed in a sequence different from those in the embodiments and thedesired result may still be achieved. In addition, the processesdescribed in the accompanying drawings do not necessarily require thespecific order or sequential order shown to achieve the desired result.In some implementation manners, multitasking and parallel processing arealso feasible or may be advantageous.

The computer instructions include computer program codes that may be insource code forms, object code forms, executable files, someintermediate form, or the like. The computer-readable medium mayinclude: any entity or device capable of carrying the computer programcode, recording medium, USB flash disk, mobile hard disk, magnetic disk,optical disk, computer memory, read-only memory (ROM), random accessmemory (RAM), electrical carrier signal, telecommunication signal,software distribution medium, and the like. It should be noted thatappropriate addition or deletion on the content contained in thecomputer-readable medium may be made in accordance with the requirementsof legislation and patent practice in a jurisdiction, for example, insome jurisdictions, the computer-readable medium may not includeelectrical carrier signals or telecommunication signals in accordancewith legislation and patent practice.

It should be noted that with regard to the above-described methodembodiments, in order to provide a simple and concise description, themethod embodiments are all expressed as a series of action combinations.Those skilled in the art, however, should know that the presentdisclosure is not limited by the described sequence of actions as somesteps may be executed in another sequence or simultaneously according tothe present disclosure. Secondly, those skilled in the art should alsoknow that the embodiments described in the present disclosure are allexample embodiments, and the involved actions and modules are notnecessarily required by the embodiments of the present disclosure.

In the above embodiments, the description of each embodiment has its ownemphasis. For any part that is not described in detail in oneembodiment, reference may be made to related descriptions in otherembodiments.

The example embodiments of the present disclosure disclosed above areprovided only to aid in the description of the present disclosure.Alternative embodiments are not intended to exhaust all details, nor dothey limit the present disclosure to only the detailed embodimentsdescribed. Apparently, many modifications and changes can be made inaccordance with the contents of the embodiments of the presentdisclosure. These embodiments are selected and described in the presentdisclosure to better explain the principles and practical applicationsof the embodiments of the present disclosure, so that those skilled inthe art can well understand and utilize the present disclosure. Thepresent disclosure is limited only by the claims and their full scopeand equivalents.

The present disclosure may further be understood with clauses asfollows.

Clause 1. A data migration method, comprising:

acquiring a migration request for a source database;

creating a snapshot of to-be-migrated data in the source database andmigrating the snapshot to a target database;

reading a data migration log stored in a primary replica database of thesource database and synchronizing the data migration log into the targetdatabase; and

configuring a route for a target primary replica database of the targetdatabase according to routing rules of the primary replica database.

Clause 2. The data migration method according to clause 1, wherein thesource database includes the primary replica database and at least onesecondary replica database; and the target database includes at leasttwo replica databases.

Clause 3. The data migration method according to clause 2, wherein thedata migration log is synchronized into the target database by:

establishing a log synchronization link based on the primary replicadatabase, the at least one secondary replica database, and the at leasttwo replica databases; and

synchronizing the data migration log into the target database accordingto an upstream-downstream connection relationship of each node in thelog synchronization link.

Clause 4. The data migration method according to clause 3, wherein thesynchronizing the data migration log into the target database accordingto an upstream-downstream connection relationship of each node in thelog synchronization link comprises:

synchronizing the data migration log from the primary replica databaseinto the at least one secondary replica database; and

synchronizing the data migration log from the at least one secondaryreplica database into the at least two replica databases.

Clause 5. The data migration method according to clause 2, wherein theconfiguring a route for a target primary replica database of the targetdatabase according to routing rules of the primary replica databasecomprises:

determining any of the replica databases contained in the targetdatabase as the target primary replica database; and

configuring a route for the target primary replica database according tothe routing rules of the primary replica database.

Clause 6. The data migration method according to clause 2, wherein thetarget primary replica database is determined by:

initiating an election to the source database based on identificationinformation of the at least two replica databases, wherein the electionis used to elect the target primary replica database from the at leasttwo replica databases;

acquiring voting results submitted by the primary replica database andthe at least one secondary replica database; and

counting the voting results, and determining one of the at least tworeplica databases first obtaining more votes than a preset threshold asthe target primary replica database.

Clause 7. The data migration method according to clause 1, wherein thecreating a snapshot of to-be-migrated data in the source database andmigrating the snapshot to a target database comprises:

creating a snapshot of full to-be-migrated data in the primary replicadatabase or any secondary replica database of the source database; and

migrating the snapshot to the target database by a preset migrationmode.

Clause 8. The data migration method according to clause 1, furthercomprising, after the step of reading a data migration log stored in aprimary replica database of the source database and synchronizing thedata migration log into the target database is performed and before thestep of configuring a route for a target primary replica database of thetarget database according to routing rules of the primary replicadatabase is performed:

judging whether the number of synchronized log entries in the datamigration log meets a preset threshold; and

if so, determining that a synchronization progress of the data migrationlog meets a preset progress threshold, and performing the step ofconfiguring the route for the target primary replica database of thetarget database according to the routing rules of the primary replicadatabase in the source database.

Clause 9. The data migration method according to clause 1, wherein themethod further comprises, after the step of configuring a route for atarget primary replica database of the target database according torouting rules of the primary replica database in the source database isperformed:

receiving a data read-write request;

searching a corresponding target primary replica database according toan identifier of requested data in the data read request; and

performing a data read-write operation on the target primary replicadatabase according to routing rules for data read-write of the targetprimary replica database.

Clause 10. A data migration device, comprising:

an acquisition module, configured to acquire a migration request for asource database;

a creation module, configured to create a snapshot of to-be-migrateddata in the source database and migrate the snapshot to a targetdatabase;

a reading module, configured to read a data migration log stored in aprimary replica database of the source database and synchronize the datamigration log into the target database; and

a configuration module, configured to configure a route for a targetprimary replica database of the target database according to routingrules of the primary replica database.

Clause 11. A computing device, comprising:

a memory and a processor;

wherein the memory is configured to store computer-executableinstructions, and the processor is configured to execute thecomputer-executable instructions to:

acquire a migration request for a source database;

create a snapshot of to-be-migrated data in the source database andmigrate the snapshot to a target database;

read a data migration log stored in a primary replica database of thesource database and synchronize the data migration log into the targetdatabase; and

configure a route for a target primary replica database of the targetdatabase according to routing rules of the primary replica database.

Clause 12. A computer-readable storage medium having computerinstructions stored thereon, which, when executed by a processor,implement the steps of the data migration method according to any one ofclauses 1-9.

What is claimed is:
 1. A method comprising: acquiring a migration request for a source database; creating a snapshot of to-be-migrated data in the source database; migrating the snapshot to a target database; reading a data migration log stored in a primary replica database of the source database; synchronizing the data migration log into the target database; and configuring a route for a target primary replica database of the target database according to one or more routing rules of the primary replica database.
 2. The method according to claim 1, wherein the source database includes the primary replica database and at least one secondary replica database.
 3. The method according to claim 2, wherein the target database includes at least two replica databases.
 4. The method according to claim 3, wherein the synchronizing the data migration log into the target database comprises: establishing a log synchronization link based on the primary replica database, the at least one secondary replica database, and the at least two replica databases; and synchronizing the data migration log into the target database according to an upstream-downstream connection relationship of multiple node in the log synchronization link.
 5. The method according to claim 4, wherein the synchronizing the data migration log into the target database according to the upstream-downstream connection relationship of multiple nodes in the log synchronization link comprises: synchronizing the data migration log from the primary replica database into the at least one secondary replica database; and synchronizing the data migration log from the at least one secondary replica database into the at least two replica databases.
 6. The method according to claim 3, wherein the configuring the route for the target primary replica database of the target database according to the one or more routing rules of the primary replica database comprises: determining a replica database contained in the target database as the target primary replica database; and configuring a route for the target primary replica database according to the one or more routing rules of the primary replica database.
 7. The method according to claim 6, further comprising determining the target primary replica database, the determining the target primary replica database including: initiating an election to the source database based on identification information of the at least two replica databases, wherein the election is used to elect the target primary replica database from the at least two replica databases; acquiring voting results submitted by the primary replica database and the at least one secondary replica database; counting the voting results; and determining one of the at least two replica databases that obtains more votes than a preset threshold as the target primary replica database.
 8. The method according to claim 7, wherein the determining one of the at least two replica databases that obtains more votes than the preset threshold as the target primary replica database includes: determining one of the at least two replica databases that firstly obtains more votes than a preset threshold as the target primary replica database.
 9. The method according to claim 1, wherein the creating the snapshot of to-be-migrated data in the source database comprises: creating a snapshot of full to-be-migrated data in the primary replica database or a secondary replica database of the source database.
 10. The method according to claim 9, wherein the migrating the snapshot to the target database comprises: migrating the snapshot to the target database by a preset migration mode.
 11. The method according to claim 1, further comprising: after the synchronizing the data migration log into the target database and before the configuring the route for the target primary replica database of the target database according to the one or more routing rules of the primary replica database, judging whether a number of synchronized log entries in the data migration log meets a preset threshold; and in response to judging that the number of synchronized log entries in the data migration log meets the preset threshold, determining that a synchronization progress of the data migration log meets a preset progress threshold.
 12. The method according to claim 1, further comprising: after the configuring the route for the target primary replica database of the target database according to the one or more routing rules of the primary replica database, receiving a data read-write request; searching the target primary replica database according to an identifier of requested data in the data read-write request; and performing a data read-write operation on the target primary replica database according to routing rules for data read-write of the target primary replica database.
 13. A device comprising: one or more processors; and one or more memories storing thereon computer-readable instructions that, when executed by the one or more processors, cause the one or more processors to perform acts comprising: acquiring a migration request for a source database; creating a snapshot of to-be-migrated data in the source database; migrating the snapshot to a target database; reading a data migration log stored in a primary replica database of the source database; synchronizing the data migration log into the target database; and configuring a route for a target primary replica database of the target database according to one or more routing rules of the primary replica database.
 14. The device according to claim 13, wherein: the source database includes the primary replica database and at least one secondary replica database; and the target database includes at least two replica databases.
 15. The device according to claim 14, wherein the synchronizing the data migration log into the target database comprises: establishing a log synchronization link based on the primary replica database, the at least one secondary replica database, and the at least two replica databases; and synchronizing the data migration log into the target database according to an upstream-downstream connection relationship of multiple node in the log synchronization link.
 16. The device according to claim 15, wherein the synchronizing the data migration log into the target database according to the upstream-downstream connection relationship of multiple nodes in the log synchronization link comprises: synchronizing the data migration log from the primary replica database into the at least one secondary replica database; and synchronizing the data migration log from the at least one secondary replica database into the at least two replica databases.
 17. The device according to claim 15, wherein the configuring the route for the target primary replica database of the target database according to the one or more routing rules of the primary replica database comprises: determining a replica database contained in the target database as the target primary replica database; and configuring a route for the target primary replica database according to the one or more routing rules of the primary replica database.
 18. The device according to claim 15, wherein the acts further comprise determining the target primary replica database, the determining the target primary replica database including: initiating an election to the source database based on identification information of the at least two replica databases, wherein the election is used to elect the target primary replica database from the at least two replica databases; acquiring voting results submitted by the primary replica database and the at least one secondary replica database; counting the voting results; and determining one of the at least two replica databases that obtains more votes than a preset threshold as the target primary replica database.
 19. The device according to claim 13, wherein the acts further comprise: after the synchronizing the data migration log into the target database and before the configuring the route for the target primary replica database of the target database according to the one or more routing rules of the primary replica database, judging whether a number of synchronized log entries in the data migration log meets a preset threshold; and in response to judging that the number of synchronized log entries in the data migration log meets the preset threshold, determining that a synchronization progress of the data migration log meets a preset progress threshold.
 20. One or more memories storing thereon computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform acts comprising: acquiring a migration request for a source database; creating a snapshot of to-be-migrated data in the source database; migrating the snapshot to a target database; reading a data migration log stored in a primary replica database of the source database; synchronizing the data migration log into the target database; and configuring a route for a target primary replica database of the target database according to one or more routing rules of the primary replica database. 